/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.vtcc.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.RowMapper;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import vn.com.fis.portal.vtcc.NoSuchStrainEntryException;
import vn.com.fis.portal.vtcc.model.StrainEntry;
import vn.com.fis.portal.vtcc.model.impl.StrainEntryImpl;
import vn.com.fis.portal.vtcc.model.impl.StrainEntryModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the strain entry service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author loind
 * @see StrainEntryPersistence
 * @see StrainEntryUtil
 * @generated
 */
public class StrainEntryPersistenceImpl extends BasePersistenceImpl<StrainEntry>
	implements StrainEntryPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link StrainEntryUtil} to access the strain entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = StrainEntryImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
			StrainEntryModelImpl.FINDER_CACHE_ENABLED, StrainEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
			StrainEntryModelImpl.FINDER_CACHE_ENABLED, StrainEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
			StrainEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the strain entry in the entity cache if it is enabled.
	 *
	 * @param strainEntry the strain entry
	 */
	public void cacheResult(StrainEntry strainEntry) {
		EntityCacheUtil.putResult(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
			StrainEntryImpl.class, strainEntry.getPrimaryKey(), strainEntry);

		strainEntry.resetOriginalValues();
	}

	/**
	 * Caches the strain entries in the entity cache if it is enabled.
	 *
	 * @param strainEntries the strain entries
	 */
	public void cacheResult(List<StrainEntry> strainEntries) {
		for (StrainEntry strainEntry : strainEntries) {
			if (EntityCacheUtil.getResult(
						StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
						StrainEntryImpl.class, strainEntry.getPrimaryKey()) == null) {
				cacheResult(strainEntry);
			}
			else {
				strainEntry.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all strain entries.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(StrainEntryImpl.class.getName());
		}

		EntityCacheUtil.clearCache(StrainEntryImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the strain entry.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(StrainEntry strainEntry) {
		EntityCacheUtil.removeResult(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
			StrainEntryImpl.class, strainEntry.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@Override
	public void clearCache(List<StrainEntry> strainEntries) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (StrainEntry strainEntry : strainEntries) {
			EntityCacheUtil.removeResult(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
				StrainEntryImpl.class, strainEntry.getPrimaryKey());
		}
	}

	/**
	 * Creates a new strain entry with the primary key. Does not add the strain entry to the database.
	 *
	 * @param strainId the primary key for the new strain entry
	 * @return the new strain entry
	 */
	public StrainEntry create(long strainId) {
		StrainEntry strainEntry = new StrainEntryImpl();

		strainEntry.setNew(true);
		strainEntry.setPrimaryKey(strainId);

		return strainEntry;
	}

	/**
	 * Removes the strain entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param strainId the primary key of the strain entry
	 * @return the strain entry that was removed
	 * @throws vn.com.fis.portal.vtcc.NoSuchStrainEntryException if a strain entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public StrainEntry remove(long strainId)
		throws NoSuchStrainEntryException, SystemException {
		return remove(Long.valueOf(strainId));
	}

	/**
	 * Removes the strain entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the strain entry
	 * @return the strain entry that was removed
	 * @throws vn.com.fis.portal.vtcc.NoSuchStrainEntryException if a strain entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public StrainEntry remove(Serializable primaryKey)
		throws NoSuchStrainEntryException, SystemException {
		Session session = null;

		try {
			session = openSession();

			StrainEntry strainEntry = (StrainEntry)session.get(StrainEntryImpl.class,
					primaryKey);

			if (strainEntry == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchStrainEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(strainEntry);
		}
		catch (NoSuchStrainEntryException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected StrainEntry removeImpl(StrainEntry strainEntry)
		throws SystemException {
		strainEntry = toUnwrappedModel(strainEntry);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, strainEntry);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(strainEntry);

		return strainEntry;
	}

	@Override
	public StrainEntry updateImpl(
		vn.com.fis.portal.vtcc.model.StrainEntry strainEntry, boolean merge)
		throws SystemException {
		strainEntry = toUnwrappedModel(strainEntry);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, strainEntry, merge);

			strainEntry.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		EntityCacheUtil.putResult(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
			StrainEntryImpl.class, strainEntry.getPrimaryKey(), strainEntry);

		return strainEntry;
	}

	protected StrainEntry toUnwrappedModel(StrainEntry strainEntry) {
		if (strainEntry instanceof StrainEntryImpl) {
			return strainEntry;
		}

		StrainEntryImpl strainEntryImpl = new StrainEntryImpl();

		strainEntryImpl.setNew(strainEntry.isNew());
		strainEntryImpl.setPrimaryKey(strainEntry.getPrimaryKey());

		strainEntryImpl.setStrainId(strainEntry.getStrainId());
		strainEntryImpl.setStrainName(strainEntry.getStrainName());
		strainEntryImpl.setDescription(strainEntry.getDescription());
		strainEntryImpl.setStatus(strainEntry.getStatus());
		strainEntryImpl.setSampleId(strainEntry.getSampleId());

		return strainEntryImpl;
	}

	/**
	 * Returns the strain entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the strain entry
	 * @return the strain entry
	 * @throws com.liferay.portal.NoSuchModelException if a strain entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public StrainEntry findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the strain entry with the primary key or throws a {@link vn.com.fis.portal.vtcc.NoSuchStrainEntryException} if it could not be found.
	 *
	 * @param strainId the primary key of the strain entry
	 * @return the strain entry
	 * @throws vn.com.fis.portal.vtcc.NoSuchStrainEntryException if a strain entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public StrainEntry findByPrimaryKey(long strainId)
		throws NoSuchStrainEntryException, SystemException {
		StrainEntry strainEntry = fetchByPrimaryKey(strainId);

		if (strainEntry == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + strainId);
			}

			throw new NoSuchStrainEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				strainId);
		}

		return strainEntry;
	}

	/**
	 * Returns the strain entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the strain entry
	 * @return the strain entry, or <code>null</code> if a strain entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public StrainEntry fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the strain entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param strainId the primary key of the strain entry
	 * @return the strain entry, or <code>null</code> if a strain entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public StrainEntry fetchByPrimaryKey(long strainId)
		throws SystemException {
		StrainEntry strainEntry = (StrainEntry)EntityCacheUtil.getResult(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
				StrainEntryImpl.class, strainId);

		if (strainEntry == _nullStrainEntry) {
			return null;
		}

		if (strainEntry == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				strainEntry = (StrainEntry)session.get(StrainEntryImpl.class,
						Long.valueOf(strainId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (strainEntry != null) {
					cacheResult(strainEntry);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(StrainEntryModelImpl.ENTITY_CACHE_ENABLED,
						StrainEntryImpl.class, strainId, _nullStrainEntry);
				}

				closeSession(session);
			}
		}

		return strainEntry;
	}

	/**
	 * Returns all the strain entries.
	 *
	 * @return the strain entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<StrainEntry> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the strain entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of strain entries
	 * @param end the upper bound of the range of strain entries (not inclusive)
	 * @return the range of strain entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<StrainEntry> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the strain entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of strain entries
	 * @param end the upper bound of the range of strain entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of strain entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<StrainEntry> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<StrainEntry> list = (List<StrainEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_STRAINENTRY);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_STRAINENTRY.concat(StrainEntryModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<StrainEntry>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<StrainEntry>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the strain entries from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (StrainEntry strainEntry : findAll()) {
			remove(strainEntry);
		}
	}

	/**
	 * Returns the number of strain entries.
	 *
	 * @return the number of strain entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_STRAINENTRY);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns all the sample entries associated with the strain entry.
	 *
	 * @param pk the primary key of the strain entry
	 * @return the sample entries associated with the strain entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.vtcc.model.SampleEntry> getSampleEntries(
		long pk) throws SystemException {
		return getSampleEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the sample entries associated with the strain entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the strain entry
	 * @param start the lower bound of the range of strain entries
	 * @param end the upper bound of the range of strain entries (not inclusive)
	 * @return the range of sample entries associated with the strain entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.vtcc.model.SampleEntry> getSampleEntries(
		long pk, int start, int end) throws SystemException {
		return getSampleEntries(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_SAMPLEENTRIES = new FinderPath(vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.FINDER_CACHE_ENABLED,
			vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl.class,
			vn.com.fis.portal.vtcc.service.persistence.SampleEntryPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getSampleEntries",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the sample entries associated with the strain entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the strain entry
	 * @param start the lower bound of the range of strain entries
	 * @param end the upper bound of the range of strain entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of sample entries associated with the strain entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.vtcc.model.SampleEntry> getSampleEntries(
		long pk, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<vn.com.fis.portal.vtcc.model.SampleEntry> list = (List<vn.com.fis.portal.vtcc.model.SampleEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_SAMPLEENTRIES,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETSAMPLEENTRIES.concat(ORDER_BY_CLAUSE)
											   .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETSAMPLEENTRIES.concat(vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("SampleEntry",
					vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<vn.com.fis.portal.vtcc.model.SampleEntry>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_SAMPLEENTRIES,
						finderArgs);
				}
				else {
					sampleEntryPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_SAMPLEENTRIES,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_SAMPLEENTRIES_SIZE = new FinderPath(vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.FINDER_CACHE_ENABLED,
			vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl.class,
			vn.com.fis.portal.vtcc.service.persistence.SampleEntryPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"getSampleEntriesSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of sample entries associated with the strain entry.
	 *
	 * @param pk the primary key of the strain entry
	 * @return the number of sample entries associated with the strain entry
	 * @throws SystemException if a system exception occurred
	 */
	public int getSampleEntriesSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SAMPLEENTRIES_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETSAMPLEENTRIESSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_SAMPLEENTRIES_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_SAMPLEENTRY = new FinderPath(vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.ENTITY_CACHE_ENABLED,
			vn.com.fis.portal.vtcc.model.impl.SampleEntryModelImpl.FINDER_CACHE_ENABLED,
			vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl.class,
			vn.com.fis.portal.vtcc.service.persistence.SampleEntryPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"containsSampleEntry",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the sample entry is associated with the strain entry.
	 *
	 * @param pk the primary key of the strain entry
	 * @param sampleEntryPK the primary key of the sample entry
	 * @return <code>true</code> if the sample entry is associated with the strain entry; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsSampleEntry(long pk, long sampleEntryPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, sampleEntryPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SAMPLEENTRY,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsSampleEntry.contains(pk,
							sampleEntryPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SAMPLEENTRY,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the strain entry has any sample entries associated with it.
	 *
	 * @param pk the primary key of the strain entry to check for associations with sample entries
	 * @return <code>true</code> if the strain entry has any sample entries associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsSampleEntries(long pk) throws SystemException {
		if (getSampleEntriesSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Initializes the strain entry persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.vn.com.fis.portal.vtcc.model.StrainEntry")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<StrainEntry>> listenersList = new ArrayList<ModelListener<StrainEntry>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<StrainEntry>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}

		containsSampleEntry = new ContainsSampleEntry();
	}

	public void destroy() {
		EntityCacheUtil.removeCache(StrainEntryImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = SampleEntryPersistence.class)
	protected SampleEntryPersistence sampleEntryPersistence;
	@BeanReference(type = StrainEntryPersistence.class)
	protected StrainEntryPersistence strainEntryPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	protected ContainsSampleEntry containsSampleEntry;

	protected class ContainsSampleEntry {
		protected ContainsSampleEntry() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSSAMPLEENTRY,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long strainId, long sampleId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(strainId), new Long(sampleId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	private static final String _SQL_SELECT_STRAINENTRY = "SELECT strainEntry FROM StrainEntry strainEntry";
	private static final String _SQL_COUNT_STRAINENTRY = "SELECT COUNT(strainEntry) FROM StrainEntry strainEntry";
	private static final String _SQL_GETSAMPLEENTRIES = "SELECT {SampleEntry.*} FROM SampleEntry INNER JOIN vtcc_strain ON (vtcc_strain.strainId = SampleEntry.strainId) WHERE (vtcc_strain.strainId = ?)";
	private static final String _SQL_GETSAMPLEENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SampleEntry WHERE strainId = ?";
	private static final String _SQL_CONTAINSSAMPLEENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM SampleEntry WHERE strainId = ? AND sampleId = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "strainEntry.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No StrainEntry exists with the primary key ";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(StrainEntryPersistenceImpl.class);
	private static StrainEntry _nullStrainEntry = new StrainEntryImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<StrainEntry> toCacheModel() {
				return _nullStrainEntryCacheModel;
			}
		};

	private static CacheModel<StrainEntry> _nullStrainEntryCacheModel = new CacheModel<StrainEntry>() {
			public StrainEntry toEntityModel() {
				return _nullStrainEntry;
			}
		};
}